<?php

namespace app\service;
use app\model\Menu;
use app\utils\Tree;

class MenuService extends BaseService
{
    protected function setModel(): string
    {
        return  Menu::class;
    }


    public function listToTree($where, $pid = 0)
    {
        $list = $this->getAll($where)->toArray();
        $list = tree_to_list($list);
        $treeService = new Tree();
        return $treeService->toFormatTree($list, "name", 'id', 'pid', $pid);
    }

    public function getTopList()
    {
        $list = $this->getAll(["status" => 1, "pid" => 0],"*","sort asc");
        return $list;
    }

    public function getGroup($where,$field)
    {
       $list = $this->getModel()->distinct(true)->where($where)->column($field);
       return $list;
    }
}